/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.mb;

import br.siagefi.model.ClientePF;
import br.siagefi.service.ClientePFService;
import java.io.Serializable;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Paulo Lavarini
 */

@SessionScoped
@ManagedBean
public class ClientePFBean implements Serializable{
    private ClientePF clientePF;
    private final ClientePFService service;
    private List<ClientePF> clientesPF;

    public ClientePFBean() {
        this.clientePF = new ClientePF();
        this.service = new ClientePFService();
        this.carregarLista();
    }
    
     public final void carregarLista(){
         this.clientesPF = service.listar();
    }
    
    public String gravar(){
        service.gravar(this.getClientePF());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "clientePF?faces-redirect=true";
    }
    
    public String alterar(ClientePF clientePF){
        this.setClientePF(clientePF);
        return "incluirClientePF";
    }
    
     public String remover(){
        service.remover(this.getClientePF());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "clientePF";
    }
     
    public String remover(ClientePF clientePF){
        service.remover(clientePF);
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "clientePF";
    }
  
    public void limparFormularioDoJsf(){
        this.clientePF = new ClientePF();
    }

    public ClientePF getClientePF() {
        return clientePF;
    }

    public void setClientePF(ClientePF clientePF) {
        this.clientePF = clientePF;
    }

    public List<ClientePF> getClientesPF() {
        return clientesPF;
    }

    public void setClientePFs(List<ClientePF> clientesPF) {
        this.clientesPF = clientesPF;
    }
   
}
